package com.example.controller;

import com.example.config.ResponseVO;
import com.example.pojo.ClassesCircle;
import com.example.pojo.dto.TeacherCircleDTO;
import com.example.service.ClassCircleService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/classesCircle")
public class ClassCircleController {
    @Resource
    ClassCircleService classCircleService;

    // 查询一个班级的班级圈所有的内容
    @GetMapping("/classCircleList/{classId}")
    public ResponseEntity<ResponseVO<List<TeacherCircleDTO>>> getClassCircleList(@PathVariable Long classId){
        List<TeacherCircleDTO> classCircleList = classCircleService.getClassesCirclesByClassId(classId);
        if (!classCircleList.isEmpty()){
            return ResponseEntity.ok(new ResponseVO<>(HttpStatus.OK,"班级圈信息获取成功",classCircleList));
        }
        return ResponseEntity.ok(new ResponseVO<>(HttpStatus.OK,"暂无班级圈信息",null));
    }

    @PostMapping("/deleteCircleById")
    public ResponseEntity<ResponseVO<String>> deleteCircleById(@RequestBody ClassesCircle circle){
        int result = classCircleService.deleteCircleById(circle);
        if (result>0){
            return ResponseEntity.ok(new ResponseVO<>(HttpStatus.OK,"删除成功"));
        }
        return ResponseEntity.ok(new ResponseVO<>(HttpStatus.BAD_REQUEST,"删除失败"));
    }

    @GetMapping("/likeClassCircle/{likesId}/{classesCircleId}")
    public ResponseEntity<ResponseVO<String>> likeClassCircle(@PathVariable Long likesId,@PathVariable Long classesCircleId){
        int result = classCircleService.likeClassCircle(likesId,classesCircleId);
        if (result>0){
            return ResponseEntity.ok(new ResponseVO<>(HttpStatus.OK,"点赞成功"));
        }
        return ResponseEntity.ok(new ResponseVO<>(HttpStatus.BAD_REQUEST,"删除失败"));
    }

    @DeleteMapping("/cancelLike/{likesId}/{classesCircleId}")
    public ResponseEntity<ResponseVO<String>> cancelLike(@PathVariable Long likesId,@PathVariable Long classesCircleId){
        int result = classCircleService.cancelLikeClassCircle(likesId,classesCircleId);
        if (result>0){
            return ResponseEntity.ok(new ResponseVO<>(HttpStatus.OK,"取消点赞成功"));
        }
        return ResponseEntity.ok(new ResponseVO<>(HttpStatus.BAD_REQUEST,"取消失败"));
    }

    @PostMapping("/addClassCircle")
    public ResponseEntity<ResponseVO<String>> addClassCircle(@RequestBody ClassesCircle circle){
        int result = classCircleService.addClassCircle(circle);
        if (result>0){
            return ResponseEntity.ok(new ResponseVO<>(HttpStatus.OK,"发布成功"));
        }
        return ResponseEntity.ok(new ResponseVO<>(HttpStatus.BAD_REQUEST,"发布失败"));
    }
}
